package com.baizhi.service.impl;

import com.baizhi.dao.UserDao;
import com.baizhi.entity.User;
import com.baizhi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;
    @Override
    public Map showUser(String userName, int page, int limit) {
        Map map=new HashMap();
        int offset=(page-1)*limit;
        List<User> list=userDao.selectUserSearchByName(userName,offset,limit);
        int count =userDao.selectSearchCount(userName);
        map.put("data",list);
        map.put("count",count);
        map.put("code",0);
        map.put("msg","");
        return map;
    }

    @Override
    public Map deleteUerById(int userId) {
        Map map=new HashMap();
        int count=userDao.deleteUerById(userId);
        if(count>0){
            map.put("isDelete",true);
        }else{
            map.put("idDelete",false);
        }
        return map;
    }

    @Override
    public List<Map> selectCountBySex() {
        List<Map> list=userDao.selectCountBySex();
        return list;
    }

    @Override
    public List<Map> selectCountByProvince() {
        List<Map> list=userDao.selectCountByProvince();
        return list;
    }

    @Override
    public Map showAll() {
        Map map=new HashMap();
        int value1=userDao.selectCountCreate1();
        int value2=userDao.selectCountCreate2();
        int value3=userDao.selectCountCreate3();
        map.put("one",value1);
        map.put("two",value2);
        map.put("three",value3);
        return map;
    }
}
